package com.layui.ad.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.layui.ad.annotation.DataSource;
import com.layui.ad.entity.BrokerInfo;
import com.layui.ad.enums.DataSourceEnum;
import com.layui.ad.exception.ServiceException;
import com.layui.ad.mapper.BrokerInfoMapper;
import com.layui.ad.service.BrokerService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import javax.sql.rowset.serial.SerialException;
import java.beans.IntrospectionException;
import java.util.Map;
import java.util.function.Function;

@Log4j2
@Service
public class BrokerServiceImpl extends ServiceImpl<BrokerInfoMapper, BrokerInfo> implements BrokerService {

    @Override
    public IPage<BrokerInfo> selectRecord(IPage<BrokerInfo> page, BrokerInfo binfo) {
        LambdaQueryWrapper<BrokerInfo> lambda = new QueryWrapper<BrokerInfo>().lambda();
        lambda.eq(BrokerInfo::getCompanysid, binfo.getCompanysid());
        if (null != binfo.getUsertitle()) {
            lambda.eq(BrokerInfo::getUsertitle, binfo.getUsertitle());
        }
        if (null != binfo.getBname()) {
            lambda.and(wrapper -> wrapper.like(BrokerInfo::getBname, binfo.getBname()).or().like(BrokerInfo::getBrokerid, binfo.getBname()).or().like(BrokerInfo::getMobile, binfo.getBname()));
        }
        baseMapper.selectPage(page, lambda);
        return baseMapper.selectPage(page, lambda);
    }

    @Override
    public Integer setBrokerStatus(Integer brokerId, Integer status) {
        return this.baseMapper.setBrokerStatus(brokerId, status);
    }

    @Override
    public Integer delBroker(Integer brokerId){
        try {
            int num = this.baseMapper.delBroker(brokerId);
            return num;
        } catch (Exception e){
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public BrokerInfo getInfoByBrokerId(Integer brokerId){
        return this.baseMapper.getInfoByBrokerId(brokerId);
    }

    @Override
    public Integer editBrokerInfo(Map brokerMap){
        return this.baseMapper.editBrokerInfo(brokerMap);
    }

}
